package org.example.spring_ioc;

import org.apache.catalina.User;
import org.example.spring_ioc.Service.UserService;
import org.example.spring_ioc.component.UserComponent;
import org.example.spring_ioc.config.UserConfig;
import org.example.spring_ioc.controller.UserController;
import org.example.spring_ioc.model.UserInfo;
import org.example.spring_ioc.repository.UserRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringIocApplication {

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);

//        //@Controller
//        UserController usercontroller = context.getBean(UserController.class);
//        System.out.println(usercontroller);
//        usercontroller.sayHi();
//
//        //@Service 三种getBean
//        UserService userService1 = context.getBean(UserService.class);
//        UserService userService2 = (UserService) context.getBean("userService");
//        UserService userService3 = context.getBean("userService", UserService.class);
//        System.out.println(userService1);//根据类型
//        System.out.println(userService2);//根据名称
//        System.out.println(userService3);//根据名称和类型
//        userService1.sayHi();
//
//        //@Repository
//        UserRepository userRepository = context.getBean(UserRepository.class);
//        System.out.println(userRepository);
//        usercontroller.sayHi();
//
//        //@Component
//        UserComponent userComponent = context.getBean(UserComponent.class);
//        userRepository.sayHi();
//
//        //@Configuration
//        UserConfig userConfig = context.getBean(UserConfig.class);
//        userConfig.sayHi();
//
//        //自定义类
//        System.out.println(context.getBean("userInfo1"));
//        System.out.println(context.getBean("userInfo2"));
//        System.out.println(context.getBean("userInfo3"));


        //spring 扫描路径默认是启动类所在路径，且加上五大注解的才会被管理
    }

}
